<html>
	<head>
		<title>localscan.html</title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<link href="../../css/general1.css" rel="stylesheet" type="text/css" />
		<link href="style/css.css" rel="stylesheet" type="text/css" />
		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<link href="../../zephyr/css/drift.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../zephyr/js/Util.js"></script>
		<script type="text/javascript" src="../../script/hiawardbpm.js"></script>
		<script type="text/javascript" src="../../script/prototype.js"></script>
		<!-- 显示控件JS -->
		<script type="text/javascript" src="../../script/idocx.js"></script>
		<script type="text/javascript" src="/vchzms-hiaward/dwr/engine.js"> </script>
		<script type="text/javascript" src="/vchzms-hiaward/dwr/util.js"> </script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/Ocx.js"></script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/OutService.js"></script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/Dao.js"></script>
		<script type="text/javascript">
            function subForm(){
                var webData = buildWebData();
                var xmlMsg = window.dialogArguments;
                alert(xmlMsg.getXmlDocument().xml);
                xmlMsg.setCommand(12);
                xmlMsg.setWebData(webData);
                xmlMsg.buildXML();
                var url = "/vchzms-hiaward/ProcessAjaxHandler";
                alert(xmlMsg.getXmlDocument().xml);
                new Ajax.Request(url, {
                    method: 'post',
                    postBody: xmlMsg.getXmlDocument().xml,
                    contentType: 'application/x-www-form-urlencoded',
                    encoding: 'UTF-8',
                    onComplete: function(transport){
                        try {
                            if (200 == transport.status) {
                                alert('成功创建了一个新任务');
                                window.document.parentWindow.location.reload();
                                window.close();
                            }
                            if (400 == transport.status) {
                                alert('创建失败');
                            }
                        } 
                        catch (err) {
                            alert('js异常');
                        }
                    }
                });
            }
            
            function buildWebData(){
                var webData = new WebData();
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                alert(vchsid);
                webData.setProperty('idresult', '2');
                webData.setProperty('idstate', '5');
                webData.setProperty('vchsidInput', vchsid);
                return webData;
            }
            		
            //查询客户信息和票据信息的函数
            function getVoucherInfo(){
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                Dao.getVoucherById(vchsid, function(rr){
                    var vd = rr.vchdate;
                    $("accno").innerHTML = rr.accno;
                    $("vchno").innerHTML = rr.vchno;
                    $("amount").value = rr.amount;
                    $("vchtype").innerHTML = rr.vchtype;
                    $("vchdate").value = rr.vchdate;
                    $("exchno").innerHTML = rr.exchno;
                    if (rr.batno != null) {
                        $("batno").innerHTML = rr.batno;
                    }
                    OutService.Z_BAPI_ACCOUNT_INFO(rr.accno, function(data){
                        var custid = data.custId;
                        $('coName').innerHTML = data.accName;
                        OutService.Z_BAPI_BP_GET_ORG_DETAIL(custid, function(data){
                            $('connector').innerHTML = data.connector;
                            $('tel').innerHTML = data.tel;
                        });
                    });
                });
                
            }
            
            function imgChange(flag){
                switch (flag) {
                    case 1:
                        $("img").innerHTML = "<object id='DOcxtest1' name='DOcxtest1' on classid='clsid:4E2CEA6C-A572-40EA-80FE-EC78F1CFA756' width=400 height=420 align=middle hspace=0 vspace=10 viewastext></object>"
                        invokeOCX();
                        break;
                    case 2:
                        $("img").innerHTML = "<img src='pic/00000001.jpg' width='500' height='283' />"
                        break;
                    case 3:
                        $("img").innerHTML = "<img src='pic/00000002.jpg' width='500' height='283' />"
                        break;
                }
            }
            
            //调用页面验印控件的函数
            function invokeOCX(commandid, xml){
                var xmldata = xml;
                var commandid = commandid;
                var DOcxtest1 = document.getElementById("scanOcx");
                var varRet = null;
                if (xmldata) {
                    varRet = DOcxtest1.Zms(commandid, xmldata);
                }
                //alert("调用控件返回xml信息: " + varRet); //调用控件返回xml信息
            }
            
            //请求验印XML
            function getTradeXML(){
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
				Ocx.getIdTradeXML(vchsid,0,'', 2, function(xml){
                    verifyIdTradeXML(xml);
                });
            }
			
			//验证报文，判断是否初始化控件
            function verifyIdTradeXML(idxml){
                //if ($('resub').style.display == '') 
                //    $('resub').style.display == 'none';
                var no = idxml.substring(0, 3);
                if (no != '') {
                    if (no == '<?x') {
                        var xmlDoc = new ActiveXObject("microsoft.xmldom");
                        xmlDoc.async = false;
                        xmlDoc.loadXML(idxml);
                        var combflag = xmlDoc.selectSingleNode("//seal/@combflag").text;
                        if (combflag != "0") {
							$('identifyMessegeBox').value = '有印件组合，金额设置为可输入';
                            $('amount').readOnly = false;
                        }
                        invokeOCX(1014, idxml);
                    }
                    else 
                        if (no != '000') {
                            if (no == 'A02') {
                                $('identifyMessegeBox').value ='查询数据不存在!';
                            }
                            else 
                                if (no == 'A15') {
                                    $('identifyMessegeBox').value = '印鉴处于变更期,出票日期设置为可输入';
                                    $('vchdate').readOnly = false;
                                    //$('resub').style.display = '';
									resub('0');
                                }
                                else {
                                    var msg = idxml.substring(3, idxml.length);
									$('identifyMessegeBox').value = msg;
                                }
                        }
                        else {
                            var xmlDoc = new ActiveXObject("microsoft.xmldom");
                            xmlDoc.async = false;
                            xmlDoc.loadXML(idxml);
                            var combflag = xmlDoc.selectSingleNode("//seal/@combflag").text;
                            if (combflag != "0") {
								$('identifyMessegeBox').value = '有印件组合，金额设置为可输入';
                                $('amount').readOnly = false;
                            }
                            invokeOCX(1014, idxml);
                        }
                }
                else {
                    $('identifyMessegeBox').value ='返回验印报文错误!';
                }
            }
            //保存验印结果
            function saveIdResult(){
            
                var DOcxtest1 = document.getElementById("scanOcx");
                var varRet = DOcxtest1.Zms(1015, "");
                alert("调用控件返回xml信息: " + varRet); //调用控件返回xml信息
                var xmlMsg = window.dialogArguments;
                var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                
                Ocx.saveIdResult(1015, varRet, vchsid, function(res){

                    //prompt("图像ID",res);

                });
            }
            //重新初始化控件
            function resub(updateFlag){
                var vchdate = $('vchdate').value;
                if (vchdate == '') {
                    alert("凭证日期为空，请重新输入");
                    return;
                }
                else {
                    var xmlMsg = window.dialogArguments;
                    var vchsid = xmlMsg.getWebData().getProperty('vchsid');
					if(updateFlag == 0) {//使用业务数据的凭证日期
						vchdate = '1';
					}
                    Ocx.getIdTradeXML(vchsid, vchdate,'', 2, function(xml){
                        verifyIdTradeXML(xml);
                    });
                }
            }
			
			function amountEnter(event) {
				var amount = $('amount');
				var vchdate = $('vchdate').value;
				if(event.keyCode==13 && !amount.readOnly){//回车事件
					var xmlMsg = window.dialogArguments;
                    var vchsid = xmlMsg.getWebData().getProperty('vchsid');
                    Ocx.getIdTradeXML(vchsid, vchdate,amount.value, 2, function(xml){
                        verifyIdTradeXML(xml);
                    });
				}
			}
			function vchdateEnter(event) {
				if(event.keyCode==13 && !$('vchdate').readOnly){
					resub(1);
				}
			}
    </script>
	</head>
	<body onload="initMask();getVoucherInfo();getTradeXML()">
		<div id="fade" class="black_overlay"></div>
		<center>
			<table width="100%" border="1" cellspacing="0" cellpadding="0"
				class="tablist1">
				<tr>
					<td width="66%" height="">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td>
								  <span id="img" style="height: 540">
								   <object id="scanOcx" name="scanOcx" on
										classid="clsid:4E2CEA6C-A572-40EA-80FE-EC78F1CFA756" width=400
										height=420 align=middle hspace=0 vspace=10 viewastext>
									</object>
								  </span>	
								</td>
							</tr>
						</table>
					</td>
					<td width="34%" height="" valign="top">
						<span style="width: 35%" class="title1"> <a name="tag"
							class="selectli1">客户信息</a> </span>
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="tablist1">

							<tr>
								<td width="24%">
									公司名称:
								</td>
								<td>
									<span id="coName"></span>
								</td>
							</tr>
							<tr>
								<td>
									联系人:
								</td>
								<td>
									<span id="connector"></span>
								</td>
							</tr>
							<tr>
								<td>
									联系电话:
								</td>
								<td>
									<span id="tel"></span>
								</td>
							</tr>
							<tr>
								<td>
									备注:
								</td>
								<td>
									<span id="remark"></span>
								</td>
							</tr>
						</table>
						<span style="width: 35%" class="title1"> <a name="tag"
							class="selectli1">票据信息</a> </span>
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="tablist1">
							<tr>
								<td width="24%" height="34">
									账号:
								</td>
								<td width="76%">
									<span id="accno"></span>
								</td>
							</tr>
							<tr>
								<td height="34">
									凭证类型:
								</td>
								<td>
									<span id="vchtype"></span>
								</td>
							</tr>
							<tr>
								<td height="34">
									批次号:
								</td>
								<td>
									<span id="batno"></span>
								</td>
							</tr>
							<tr>
								<td height="34">
									凭证号:
								</td>
								<td>
									<span id="vchno"></span>
								</td>
							</tr>
							<tr>
								<td height="34">
									凭证金额:
								</td>
								<td>
									<input type="text" id="amount" readonly=true onkeydown="amountEnter(event)"/>
								</td>
							</tr>
							<tr>
								<td height="34">
									凭证日期:
								</td>
								<td>
									<input type="text" id="vchdate" readonly=true onkeydown="vchdateEnter(event)"/><!--input type="button" id="resub" value="提交" class="btn1" style="display:none" onClick="resub('1')"/-->
								</td>
							</tr>
							<tr>
								<td height="34">
									交&nbsp;换&nbsp;号:
								</td>
								<td>
									<span id="exchno"></span>
								</td>
							</tr>

							<tr>
								<td height="34">
									经办柜员:
								</td>
								<td>
									<span id="idclkno">黄兵</span>
								</td>
							</tr>
						</table>
						<input id="identifyMessegeBox" name="identifyMessegeBox" style="color:#FF0000;border:0px" value="" readonly="true" size="32"/>
				</tr>
			</table>
			<table width="40%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" valign="bottom">
						<label>
							<input type="button" name="Submit" value="保 存" class="btn1"
								onclick="saveIdResult();subForm()" />
						</label>
						<label>
							<input type="button" name="Submit2" value="下一条" class="btn1" />
						</label>
						<input type="button" name="Submit3" value="关闭"
							onClick="self.close()" class="btn1" />
					</td>
				</tr>
			</table>
		</center>
	</body>
</html>
